package cc.rengu.oltp.service.common.enums;

import cc.rengu.oltp.utility.util.StringUtil;

/**
 * 交易类型枚举
 * Created by 王成 on 2020/2/21.
 */
public enum TransTypeEnum {
    MANAGE("00", "管理类交易"),
    PAY("01", "支付类交易"),
    REVSAL("02", "冲正类交易"),
    CANCEL("03", "撤销类交易"),
    REFUND("04", "退款类交易"),
    CONFIRM("05", "确认类交易"),
    AUTH("06", "授权类交易"),
    NOTIFY("07", "通知类交易"),
    ADJUST("08", "调账类交易");

    private String transType;
    private String transDesc;

    TransTypeEnum(String transType, String transDesc) {
        this.transType = transType;
        this.transDesc = transDesc;
    }

    public String getTransType() {
        return transType;
    }

    public void setTransType(String transType) {
        this.transType = transType;
    }

    public String getTransDesc() {
        return transDesc;
    }

    public void setTransDesc(String transDesc) {
        this.transDesc = transDesc;
    }

    /**
     * 根据交易码获取交易类型
     *
     * @param txnNum 交易码
     * @return 交易类型枚举
     */
    public static TransTypeEnum getTransType(String txnNum) {
        for (TransTypeEnum transTypeEnum : TransTypeEnum.values()) {
            if (!StringUtil.isEmptyOrNull(txnNum) && txnNum.substring(1, 3).equals(transTypeEnum.getTransType())) {
                return transTypeEnum;
            }
        }
        return null;
    }
}
